From d2f37f8894df81cefbdc12f555232179f6babfaa Mon Sep 17 00:00:00 2001 From: GPSBabel <12013583+GPSBabelDeveloper@users.noreply.github.com> Date: Mon, 23 May 2022 16:24:55 -0500 Subject: [PATCH] Remove xstrappend (#878) * PDF maker: format screen and input same. Shrink padding slightly. * Use reference counted pointers instead of managing our own. Fixes a leak when using debug printing. * Remove the last remaining caller of xstrappend and thus, that c-era utility. Co-authored-by: Robert Lipe --- defs.h | 1 - garmin_gpi.cc | 4 ++-- garmin_txt.cc | 18 +++++++++++------- util.cc | 20 -------------------- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/defs.h b/defs.h index 99ea2945b..8e8e698ee 100644 --- a/defs.h +++ b/defs.h @@ -1037,7 +1037,6 @@ void* xrealloc(void* p, size_t s); void xfree(const void* mem); char* xstrdup(const QString& s); char* xstrndup(const char* str, size_t sz); -char* xstrappend(char* src, const char* newd); char* xstrdup(const char* s); FILE* xfopen(const char* fname, const char* type, const char* errtxt); diff --git a/garmin_gpi.cc b/garmin_gpi.cc index 57a08a65b..696c62d27 100644 --- a/garmin_gpi.cc +++ b/garmin_gpi.cc @@ -562,11 +562,11 @@ GarminGPIFormat::read_tag(const char* caller, const int tag, Waypoint* wpt) gbfread(b.get(), 1, sz, fin); fprintf(stderr, "\n"); for (x = 0; x < sz; x++) { - fprintf(stderr, "%02x ", b[x]); + fprintf(stderr, "%02x ", b[x]); } fprintf(stderr, "\n"); for (x = 0; x < sz; x++) { - fprintf(stderr, "%c", isalnum(b[x]) ? b[x] : '.'); + fprintf(stderr, "%c", isalnum(b[x]) ? b[x] : '.'); } fprintf(stderr, "\n"); } diff --git a/garmin_txt.cc b/garmin_txt.cc index 32c0d5600..6b0fcd0a3 100644 --- a/garmin_txt.cc +++ b/garmin_txt.cc @@ -186,15 +186,19 @@ get_option_val(const char* option, const char* def) static void init_date_and_time_format() { - const char* f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT); - date_time_format = convert_human_date_format(f); + // This is old, and weird, code.. date_time_format is a global that's + // explicitly malloced and freed elsewhere. This isn't very C++ at all, + // but this format is on its deathbead for deprecation. + const char* d = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT); + char* d1 = convert_human_date_format(d); - date_time_format = xstrappend(date_time_format, " "); + const char* t = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT); + char* t1 = convert_human_time_format(t); - f = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT); - const char* c = convert_human_time_format(f); - date_time_format = xstrappend(date_time_format, c); - xfree((void*) c); + xasprintf(&date_time_format, "%s %s", d1, t1); + + xfree(d1); + xfree(t1); } static void diff --git a/util.cc b/util.cc index 9007b68e7..a1d9d9a2e 100644 --- a/util.cc +++ b/util.cc @@ -139,26 +139,6 @@ xrealloc(void* p, size_t s) return o; } -/* -* For an allocated string, realloc it and append 's' -*/ -char* -xstrappend(char* src, const char* newd) -{ - if (!src) { - return xstrdup(newd); - } - if (!newd) { - return xstrdup(src); - } - - size_t newsz = strlen(src) + strlen(newd) + 1; - src = (char*) xrealloc(src, newsz); - strcat(src, newd); - - return src; -} - /* * Wrapper for open that honours - for stdin, stdout, unifies error text. */ -- 2.30.2